package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        Class cla= Class.forName("reflect.Teacher");
        Object obj=cla.newInstance();

        Field field=cla.getField("name");
        field.set(obj,"范传奇");

        Field field1=cla.getField("age");
        field1.set(obj,20);
        System.out.println(obj);

        //获取属性值
        Object v=field.get(obj);
        System.out.println(v);
        System.out.println(field1.get(obj));
    }
}
